<extend name="Public/base"/>

<block name="body">
  <div class="main-title">
    <h2>
      {$info['id']?'编辑':'新增'}广告
    </h2>
  </div>
  <!-- <form action="{:U()}" method="post" class="form-horizontal" enctype="multipart/form-data"> -->
  <notempty name="info.id">
    <form action="{:U('Slider/edit',array('id' => $info['id']))}" method="post" class="form-horizontal" enctype="multipart/form-data">
    <else/>
    <form action="{:U('Slider/add')}" method="post" class="form-horizontal" enctype="multipart/form-data">
  </notempty>
    <div class="form-item">
      <label class="item-label">广告标题<span class="check-tips">（用于显示的文字）</span></label>
      <div class="controls">
        <input type="text" class="text input-large" name="title" value="{$info.title|default=''}">
      </div>
    </div>
    <div class="form-item">
      <label class="item-label">广告连接<span class="check-tips">（用于调转的URL，支持带http://的URL或U函数参数格式）</span></label>
      <div class="controls">
        <input type="text" class="text input-large" name="url" value="{$info.url|default=''}">
      </div>
    </div>
    <notempty name="info.save_name">
    <div class="form-item">
      <label class="item-label">原图片<span class="check-tips">（原广告轮播图）</span></label>
      <div class="controls">
          <img src="./Uploads/{$info.save_path}{$info.save_name}" alt="{$info.title}" width="200">
      </div>
    </div>
    </notempty>
    
    <div class="form-item">
      <label class="item-label">广告图片上传<span class="check-tips">（图片格式1920×830）</span></label>
      <div class="controls">
        <input type="file" class="text input-large" name="picture" multiple="multiple">
      </div>
    </div>
    <!-- <div class="form-item">
        <label class="item-label">新窗口打开<span class="check-tips">（是否新窗口打开链接）</span></label>
        <div class="controls">
            <select name="target">
              <option value="0" <eq name="info.target" value="0" >selected</eq>>否</option>
              <option value="1" <eq name="info.target" value="1" >selected</eq>>是</option>
            </select>
        </div>
    </div> -->
    <div class="form-item">
      <label class="item-label">优先级<span class="check-tips">（广告显示顺序）</span></label>
      <div class="controls">
        <input type="text" class="text input-small" name="sort" value="{$info.sort|default='0'}">
      </div>
    </div>
    <div class="form-item">
      <input type="hidden" name="id" value="{$info.id|default=''}">
      <button class="btn submit-btn" id="submit" type="submit" target-form="form-horizontal">确 定</button>
      <!-- <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button> -->
      <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
    </div>
  </form>
</block>
<block name="script">
<empty name="info.id">
<!-- 添加时用的js验证 -->
<script type="text/javascript" charset="utf-8">
  //广告高亮
  highlight_subnav('{:U('slider/index')}');

  $('#submit').click(function(){
    var title = $("input[name='title']").val();
    var file = $("input[name='picture']").val();
    var url_path = $("input[name='url']").val();

    if(!title){
      updateAlert('广告标题不能为空');
      $(this).attr({disabled:'disabled'});
      setTimeout(function(){
        location.href="{:U('Slider/add')}";
      },1500);
      return false;
    }else if(!url_path){
      updateAlert('URL不能为空');
      setTimeout(function(){
        $(this).removeClass('disabled').prop('disabled',false);
        location.href="{:U('Slider/add')}";
      },1500);
      return false;
    }else if(!file){
      updateAlert('请选择上传图片');
      setTimeout(function(){
        $(this).removeClass('disabled').prop('disabled',false);
        location.href="{:U('Slider/add')}";
      },1500);
      return false;
    }
    
  });
</script>
<else/>
<!-- 编辑时使用的js验证 -->
<script type="text/javascript" charset="utf-8">
  //广告高亮
  highlight_subnav('{:U('slider/index')}');

  $('#submit').click(function(){
    var title = $("input[name='title']").val();
    var file = $("input[name='picture']").val();
    var url_path = $("input[name='url']").val();

    if(!title){
      updateAlert('广告标题不能为空');
      $(this).attr({disabled:'disabled'});
      setTimeout(function(){
        location.href="{:U('Slider/edit',array('id' => $info['id']))}";
      },1500);
      return false;
    }else if(!url_path){
      updateAlert('URL不能为空');
      setTimeout(function(){
        $(this).removeClass('disabled').prop('disabled',false);
        location.href="{:U('Slider/edit',array('id' => $info['id']))}";
      },1500);
      return false;
    }
    
  });
</script>
</empty>
</block>
